package ink.lvxin.datastructure.utils;

public class StringUtils {
    public static String join(Object[] arr, String seperator) {
        if (arr == null || arr.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (Object o : arr) {
            sb.append(o).append(seperator);
        }

        sb.delete(sb.length() - seperator.length(),sb.length());

        return sb.toString();
    }
    public static String join(int[] arr, String seperator) {
        if (arr == null || arr.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (int o : arr) {
            sb.append(o).append(seperator);
        }

        sb.delete(sb.length() - seperator.length(),sb.length());

        return sb.toString();
    }

    public static void main(String[] args) {
        Integer[] arr = {3, 34, 5, 235, 235, 235, 25, 36, 434, 2314, 343};
        System.out.println(join(arr,","));
    }

    public static String getSpaceStrByLength(int length) {
        StringBuilder sb = new StringBuilder();
        if (length <= 0) {
            return "";
        }

        for (int i = 0; i < length; i++) {
            sb.append(" ");
        }

        return sb.toString();
    }
}
